package 历年真题;

import java.util.Scanner;

/**
 * Created by stevenfen on 2017/3/25.
 */
public class q25 {

    public static int station = 0;
    /**
     * 判断该格子是否可以填数字
     * @param x
     * @param y
     * @param array
     * @return
     */
    private  static boolean check(int x,int y,int[][] array){
        int rowNum = array.length;
        int colNum = array[0].length;

        if(x>=rowNum || x<0|| y>=colNum || y<0){
            return false;
        }

        if(array[x][y]!=0){
            return false;
        }

        return true;
    }

    /**
     * 调转方向
     * @param station
     * @return
     */
    private static int chageStation(int station){
        station = (station+1)%4;
        return station;
    }

    private static void print(int[][] array){
        int rowNum = array.length;
        int colNum = array[0].length;

        for(int i=0;i<rowNum;i++){
            for(int j=0;j<colNum;j++){
                System.out.print(array[i][j] + " ");
            }
            System.out.println("");
        }
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int size = scanner.nextInt();
        scanner.nextLine();
        int x =0;int y =-1;
        int[][] array = new int[size][size];

        //初始化
        for(int i=0;i<size;i++){
            for(int j =0;j<size;j++){
                array[i][j] = 0;
            }
        }


        for(int i=1;i<=size*size;i++){

            int originX = x,originY = y;
            if(station==0){
                y = y+1;
            }else if(station==1){
                x = x+1;
            }else if(station == 2){
                y-=1;
            }else{
                x-=1;
            }

            if(!check(x,y,array)){
                station = chageStation(station);
                x = originX;
                y = originY;
                i--;
            }else{
                array[x][y] = i;
            }
        }

        print(array);
    }
}
